package fr.utbm.VI51.lemmings_world_editor;

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * @author Belabbas Tarik - Hoffer Adrien - Perradin Vincent - Vinson Guillaume
 */

public class BrushSizePanel extends JPanel{
	
	/**
	 * @author Belabbas Tarik - Hoffer Adrien - Perradin Vincent - Vinson Guillaume
	 */
	private static final long serialVersionUID = 4689298254443919062L;
	private JSlider brushSizeSlider;
	private int brushSize;
	
	public BrushSizePanel(String sTitle){
		
		this.setBrushSize(5);
		
		// Borders
		setLayout (new FlowLayout());
		Border border = BorderFactory.createLineBorder(Color.BLACK);
		setBorder(border);
		setBorder(BorderFactory.createTitledBorder(border, sTitle, TitledBorder.CENTER, TitledBorder.TOP));
		
		this.brushSizeSlider = new JSlider(SwingConstants.HORIZONTAL, 1, 10, 5);
		this.brushSizeSlider.setSnapToTicks(true);
		this.brushSizeSlider.setMinorTickSpacing(1);
		this.brushSizeSlider.setMajorTickSpacing(3);
		this.brushSizeSlider.setPaintTicks(true);
		this.brushSizeSlider.setPaintLabels(true);
		
		// Listener
		this.brushSizeSlider.addChangeListener(new ChangeListener(){
			@Override
			public void stateChanged(ChangeEvent e){
				JSlider source = (JSlider)e.getSource();
				if (!source.getValueIsAdjusting()) {
					BrushSizePanel.this.setBrushSize(source.getValue());
				}
			}
		});
		
		this.add(this.brushSizeSlider);
		
	}

	/**
	 * @param brushSize the brushSize to set
	 */
	public void setBrushSize(int brushSize) {
		this.brushSize = brushSize;
	}

	/**
	 * @return the brushSize
	 */
	public int getBrushSize() {
		return this.brushSize;
	}
		
}
